-
Notifications
You must be signed in to change notification settings - Fork 58
Improve Exports #686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Exports #686
Conversation
🦋 Changeset detectedLatest commit: 3a6cae5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…mmonjs+node16 resolution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great - the arethetypeswrong tool and docs gives by far the best explanation I've seen of the issues and what needs to be done to fix them.
Overview
The PowerSync Node.js SDK currently provides both ESM and CommonJS exports for compatibility with different environments. However, some related packages such as the Drizzle and Kysely drivers export ESM JavaScript without explicitly declaring the package as an ES module.
While this isn't an issue for bundled applications, it causes problems when the packages are imported directly into a Node.js application. In such cases, Node.js assumes the packages use CommonJS and fails to load them due to the presence of ESM syntax like
import
andexport
.For additional context. See microsoft/TypeScript#60663
This PR updates the affected packages to explicitly export both ESM and CommonJS (now added via Rollup). As with other packages in this repo - modules are compiled with TypeScript by targeting ES. Rollup is used to compile a CommonJS export which is declared in the
package.json
file.A small test suite has also been added to verify that the packages load correctly in both environments.
A test for checking package exports via the Are The Types Wrong CLI has been added for relevant packages. Most packages have been updated with tests. Testing focus has been applied to packages which might be used in a Node.js environment. React native specific packages are not modified in this PR.
Package Changes Summary
@powersync/attachments
: Added a CJS export which is generated via Rollup.@powersync/common
: Added CJS Type declarations.@powersync/drizzle-driver
: Added a CJS export which is generated via Rollup.@powersync/kysely-driver
: Added a CJS export which is generated via Rollup.@powersync/node
: Added CJS Type declarations@powersync/react
: Declared the module as amodule
. We currently only provide ES exports for this package.@powersync/vue
: Declared the module as amodule
. We currently only provide ES exports for this package.@powersync/tanstack-react-query
: Declared the module as amodule
. We currently only provide ES exports for this package.